﻿using BlueportCoffee.model;
using System;
using System.IO.Ports;
using System.Linq;
using System.Threading;

namespace BlueportCoffee.WaterModel
{
    public class WaterMsg
    {
        private static WaterMsg instance;
        private WaterMsg() { }
        public static WaterMsg Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new WaterMsg();
                }
                return instance;
            }
        }
        public void IOSerial_Thr()
        {
            try
            {
                var ddd = SerialPort.GetPortNames().ToList();
                if (!SerialPort.GetPortNames().ToList().Any(a => a.ToLower().Contains(IPorPortInfo.Instance.WaterPortName)))
                {
                    Thread.Sleep(1000);
                    IOSerial_Thr();
                }
                WaterSerialPort.Instance.IceMachineConnect(IPorPortInfo.Instance.WaterPortName, 38400, "", 8, 1);//其他串口通讯
                //WaterSerialPort.Instance.serialPort.DataReceived += SerialPort_DataReceived;
                //Thread All_thr = new Thread(AllMassage);
                //All_thr.IsBackground = true;
                //All_thr.Start();
            }
            catch (Exception)
            {
                //IceMakingSerialPort.Instance.serialPort.DataReceived -= SerialPort_DataReceived;
                //Thread.Sleep(1000);
                //IceInit++;
                //if (IceInit == 20)
                //{
                //    //EmailShow emailShow = new EmailShow();
                //    //emailShow.content = EmailError();
                //    //var saves1 = JsonConvert.SerializeObject(emailShow);
                //    //var dd1 = HttpMsg.Instance.sendEmailMsg(saves1);
                //}
                IOSerial_Thr();
            }
        }
    }
}
